﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace ElingOA6_Admin_DSJCJ.BLL
{
    /// <summary>
    /// 部门岗位BLL
    /// </summary>
    public class HRPosition
    {
        /// <summary>
        /// 部门岗位DAL
        /// </summary>
        private readonly DAL.HRPosition dal = new DAL.HRPosition();
        /// <summary>
        /// 构造方法
        /// </summary>
        public HRPosition()
        { }
        /// <summary>
        /// 获取部门岗位数据
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="deptNo">部门编号</param>
        /// <param name="entityNo">组织机构编号</param>
        /// <returns>部门下岗位DS</returns>
        public List<Model.HRPosition> GetListByDeptNo(string deptNo, string entityNo)
        {
            DataSet ds = dal.GetListByDeptNo(deptNo, entityNo);
            return DataTableToList(ds.Tables[0]);
        }

        /// <summary>
        /// 获取所有岗位数据 编号、名称、部门
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="entityNo">组织机构编号</param>
        /// <returns>所有岗位数据列表</returns>
        public List<Model.HRPosition> GetListByEntityNo(string entityNo)
        {
            DataSet ds = dal.GetListByEntityNo(entityNo);
            return DataTableToListPart(ds.Tables[0]);
        }

        /// <summary>
        ///  获得数据列表 FPositionNo,FDeptNo,FPositionName
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="dt">需转换DT</param>
        /// <returns>转换后列表</returns>
        public List<Model.HRPosition> DataTableToListPart(DataTable dt)
        {
            List<Model.HRPosition> modelList = new List<Model.HRPosition>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Model.HRPosition model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Model.HRPosition();
                    if (dt.Rows[n]["FPositionNo"] != null && dt.Rows[n]["FPositionNo"].ToString() != "")
                    {
                        model.FPositionNo = dt.Rows[n]["FPositionNo"].ToString();
                    }
                    if (dt.Rows[n]["FDeptNo"] != null && dt.Rows[n]["FDeptNo"].ToString() != "")
                    {
                        model.FDeptNo = dt.Rows[n]["FDeptNo"].ToString();
                    }
                    if (dt.Rows[n]["FPositionName"] != null && dt.Rows[n]["FPositionName"].ToString() != "")
                    {
                        model.FPositionName = dt.Rows[n]["FPositionName"].ToString();
                    }
                    if (dt.Rows[n]["FPositionProp"] != null && dt.Rows[n]["FPositionProp"].ToString() != "")
                    {
                        model.FPositionProp = dt.Rows[n]["FPositionProp"].ToString();
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }


        /// <summary>
        /// 增加一条数据
        ///<creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="model">岗位信息</param>
        /// <returns>是否增加成功</returns>
        public bool Add(Model.HRPosition model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        ///<creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="model">岗位信息</param>
        /// <returns>是否更新成功</returns>
        public bool Update(Model.HRPosition model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        ///<creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="fPositionNo">岗位编号</param>
        /// <param name="fDeptNo">部门编号</param>
        /// <param name="fEntityNo">组织机构编号</param>
        /// <returns>是否删除成功</returns>
        public bool Delete(string fPositionNo, string fDeptNo, string fEntityNo)
        {

            return dal.Delete(fPositionNo, fDeptNo, fEntityNo);
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        /// <param name="fPositionNo">岗位编号</param>
        /// <param name="fDeptNo">部门编号</param>
        /// <param name="fEntityNo">组织机构编号</param>
        /// <returns>是否存在该记录</returns>
        public bool Exists(string fPositionNo, string fDeptNo, string fEntityNo)
        {
            return dal.Exists(fPositionNo, fDeptNo, fEntityNo);
        }


        /// <summary>
        /// 获取部门正级的岗位编号
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="deptNo">部门编号</param>
        /// <param name="entityNo">组织机构代码</param>
        /// <param name="prop">性质</param>
        /// <returns>正级岗位编号</returns>
        public string GetByPositionProp(string deptNo, string entityNo, string prop)
        {
            return dal.GetByPositionProp(deptNo, entityNo, prop);
        }



        /// <summary>
        /// 得到一个实体对象
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="fPositionNo">岗位编号</param>
        /// <param name="fDeptNo">部门编号</param>
        /// <param name="fEntityNo">组织机构编号</param>
        /// <returns>岗位信息</returns>
        public Model.HRPosition GetModel(string fPositionNo, string fDeptNo, string fEntityNo)
        {

            return dal.GetModel(fPositionNo, fDeptNo, fEntityNo);
        }
        	

        /// <summary>
        /// 获得数据列表
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="dt">需转换数据源</param>
        /// <returns>转换后数据列表</returns>
        public List<Model.HRPosition> DataTableToList(DataTable dt)
        {
            List<Model.HRPosition> modelList = new List<Model.HRPosition>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Model.HRPosition model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Model.HRPosition();
                    if (dt.Rows[n]["FPositionNo"] != null && dt.Rows[n]["FPositionNo"].ToString() != "")
                    {
                        model.FPositionNo = dt.Rows[n]["FPositionNo"].ToString();
                    }
                    if (dt.Rows[n]["FDeptNo"] != null && dt.Rows[n]["FDeptNo"].ToString() != "")
                    {
                        model.FDeptNo = dt.Rows[n]["FDeptNo"].ToString();
                    }
                    if (dt.Rows[n]["FEntityNo"] != null && dt.Rows[n]["FEntityNo"].ToString() != "")
                    {
                        model.FEntityNo = dt.Rows[n]["FEntityNo"].ToString();
                    }
                    if (dt.Rows[n]["FPositionName"] != null && dt.Rows[n]["FPositionName"].ToString() != "")
                    {
                        model.FPositionName = dt.Rows[n]["FPositionName"].ToString();
                    }
                    if (dt.Rows[n]["FSeq"] != null && dt.Rows[n]["FSeq"].ToString() != "")
                    {
                        model.FSeq = int.Parse(dt.Rows[n]["FSeq"].ToString());
                    }
                    if (dt.Rows[n]["FPositionProp"] != null && dt.Rows[n]["FPositionProp"].ToString() != "")
                    {
                        model.FPositionProp = dt.Rows[n]["FPositionProp"].ToString();
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }


    }
}
